package com.example.apple.paopo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.apple.paopo.R;
import com.orhanobut.logger.Logger;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by apple on 17/12/26.
 */

public class mFoundImageAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private LayoutInflater inflater;
    private ArrayList<String> mdatas;
    public mFoundImageAdapter(Context mContext, ArrayList<String> datas) {
        this. mContext=mContext;
        this. mdatas=datas;
        Logger.d("初始化时图片数据"+mdatas);
        inflater=LayoutInflater. from(mContext);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.mfoundimageadapter_item,parent, false);
        MyViewHolder holder= new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       MyViewHolder myViewHolder=(MyViewHolder)holder;
        ImageOptions imageOptions= new ImageOptions.Builder()
                .setFadeIn(true)
                .setCrop(true).setSize(90,65)
                .build(); //淡入效果
//ImageOptions.Builder()的一些其他属性：
//.setCircular(true) //设置图片显示为圆形
//                .setSquare(true) //设置图片显示为正方形
//                .setCrop(true).setSize(200,200) //设置大小
//                .setAnimation(animation) //设置动画
//                .setFailureDrawable(Drawable failureDrawable) //设置加载失败的动画
//                .setFailureDrawableId(int failureDrawable) //以资源id设置加载失败的动画
//.setLoadingDrawable(Drawable loadingDrawable) //设置加载中的动画
//                .setLoadingDrawableId(int loadingDrawable) //以资源id设置加载中的动画
//.setIgnoreGif(false) //忽略Gif图片
//                .setParamsBuilder(ParamsBuilder paramsBuilder) //在网络请求中添加一些参数
//                .setRaduis(int raduis) //设置拐角弧度
//.setUseMemCache(true) //设置使用MemCache，默认true
        Logger.d(position+"绑定"+mdatas.get(position));
        x.image().bind(myViewHolder.mfoundimage_image,mdatas.get(position) , imageOptions);
    }

    @Override
    public int getItemCount() {
//        Logger.d("照片"+mdatas.size());
        return mdatas.size();
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView mfoundimage_image;
        public MyViewHolder(View view) {
            super(view);
            mfoundimage_image = (ImageView) view.findViewById(R.id.mfoundimage_image);
        }
    }
}
